﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;

namespace VINETLIFE.AdminCP
{
    public partial class ListProperty : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            tlProperties.DataSource = new cmsPropertiesBL().SelectAll();
            tlProperties.DataBind();
            tlProperties.ExpandToLevel(3);
        }
        protected void lbtnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Properties.aspx");
        }

        protected void ddlParentCate_SelectedIndexChanged(object sender, EventArgs e)
        {
            int productCategoryID = int.Parse(ddlParentCate.SelectedValue);
            grvPropertyDataSource(productCategoryID);
        }
        protected void grvPropertyDataSource(int productCategoryID)
        {
            tlProperties.DataSource = new cmsPropertiesBL().SelectByProductCategory(productCategoryID);
            tlProperties.DataBind();
            tlProperties.ExpandToLevel(3);
        }
        protected void tlProperties_StartNodeEditing(object sender, DevExpress.Web.ASPxTreeList.TreeListNodeEditingEventArgs e)
        {
            int id = 0;
            if (int.TryParse(tlProperties.EditingNodeKey, out id))
            {
                Response.Redirect("Properties.aspx?Pid=" + id.ToString());
            }
        }
        protected void tlProperties_NodeDeleted(object sender, DevExpress.Web.Data.ASPxDataDeletedEventArgs e)
        {
            new cmsPropertiesBL().Delete(new cmsPropertiesDO() { PropertyID = int.Parse(tlProperties.FocusedNode.Key) });
            Response.Redirect("ListProperty.aspx");
        }
    }
}